#coding=utf-8
__author__ = 'liubin'

from project.tools import Base
from sqlalchemy import Column, Integer, String, BigInteger, ForeignKey, Boolean, Text
from sqlalchemy.orm import relationship, backref
from sqlalchemy.sql.expression import text
from project.tools import JsonpickleMixin
from base import BaseModel


class Unit(BaseModel, Base):
    """
    单位表
    """
    __tablename__ = 'm_unit'
    # 单位缩写(m, kg)
    code = Column('code', String(50), nullable=False, doc=u'编码')
    # 单位名称
    name = Column('name', String(200), nullable=False, doc=u'名称')
    # 是否基本单位(默认设置千克为基本单位)
    isBasic = Column('is_basic', Boolean, server_default=text('0'), doc=u'是否基本单位')
    isDeleted = Column('is_deleted', Boolean, server_default=text('FALSE'), doc=u'是否已删除')

    def __init__(self, data=None):
        """
        初始化
        :param data:
        :return:
        """
        if data:
            self.code = data.get('code')
            self.name = data.get('name')
            self.isBasic = data.get('isBasic')